package com.timoon.webcomponent.utility.product.discount;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.resource.PackageResourceReference;

import com.timoon.sample.dao.model.Product;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class Discount1Panel extends Panel {
	
	//通过这两个type指定两个商品
	public int DISCOUNT1_PRODUCT1_TYPE=85132447;
	public int DISCOUNT1_PRODUCT2_TYPE=85882447;
	
	
	private Discount1Service service;
	
	public Discount1Panel(String id,Discount1Service service) {
		super(id);
		// TODO Auto-generated constructor stub
		
		this.service=service;
		
		renderPanel();
		
	}

	private void renderPanel() {
		// TODO Auto-generated method stub
		
		renderProduct1();
		
		renderProduct2();
	}

	private void renderProduct1() {
		// TODO Auto-generated method stub
		Product product=this.service.getProductByType(DISCOUNT1_PRODUCT1_TYPE);
		
		if(product==null){
			throw new RuntimeException("没有找到[type="+DISCOUNT1_PRODUCT1_TYPE+"]的product");
		}
		
		add(new Image("wk_img1",new PackageResourceReference(this.getClass(),"name.jpg")));
		
		add(new Label("wk_name1",product.getName()));
		
		add(new Label("wk_instruction1",product.getInstruction()));
		
	}

	private void renderProduct2() {
		// TODO Auto-generated method stub
		Product product=this.service.getProductByType(DISCOUNT1_PRODUCT2_TYPE);
		
		if(product==null){
			throw new RuntimeException("没有找到[type="+DISCOUNT1_PRODUCT2_TYPE+"]的product");
		}
		
		add(new Image("wk_img2",new PackageResourceReference(this.getClass(),"name.jpg")));
		
		add(new Label("wk_name2",product.getName()));
		
		add(new Label("wk_instruction2",product.getInstruction()));
	}

}
